<?
/**
 * appRain CMF
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Team. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 *
 * Official Website
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/docs
 */
?>

<form method="post" action="<?php echo $this->baseUrl("/page/manage/{$action}/{$id}");?>" id="auto_chk_submit" class="pagemanager_form" >
<?php
	App::Helper('Toolbar')->setTitle("Page Manager");    
    if(isset($id)) {
        App::Helper('Toolbar')->setBtnSave()->setBtnDelete()->setBtnfileManager()->setBtnCustomHtml(App::Helper("Html")->ButtonTag("Button[View][Page]","View Page",array("onclick"=>"document.location='" . $this->baseurl("/page/view/{$id}") . "';")));
    }
    else {
        App::Helper('Toolbar')->setBtnSave()->setBtnfileManager();
    }
    App::Helper('Toolbar')->setBtnBack()->Render(array('code'=>'page_manager_top'));
?>

<?php
    $Grid = App::Module('DataGrid')->setDisplay('FormListing');
	
	if( $action == 'create'){
		$Grid->addRow(
			$this->__("Name " . App::Helper('Html')->helpTag('page-manager-page-name')),
			App::Helper("Html")
				->inputTag(
					"data[Page][name]",
					"",
					array(
						"class" => "app_input check_notempty",
						"longdesc"=>"Please a page name",
						"id" => "page_name"
					)
				)
			);
	}
	else {
		$Grid->addRow(
			$this->__("Select Page" . App::Helper('Html')->helpTag('page-manager-select-page')),			
			App::Module('AdminPanelUi')->pageNameInputBox($action,'Content',$id) . ' '  . 
			App::Helper('Html')->selectTag(
				'data[Page][rendertype]',
				array(
					''=>'Render Type',
					'h_link'=>'Link',
					'smart_h_link'=>'Smart Link',
					'text'=>'Text'
				),
				App::PageManager()->FieldValueById($id,'rendertype')
			) . 
			App::Helper('Html')->helpTag('page-manager-rendertype') 
		)
		->addRow(
			$this->__("Select Placeholder" . App::Helper('Html')->helpTag('page-manager-placeholder')),
			App::Module('AdminpanelUI')->getPagemanagerHookList($this->theme,$id)
		);
	}
?>

<?php
    if( App::Config()->Setting('disable_page_meta_options') != "Yes"){
        $Grid->addRow(
			$this->__("Page Meta Title" . App::Helper('Html')->helpTag('page-manager-meta-title')),
			App::Helper("Html")->textareaTag(
				'data[Page][page_title]',
				App::PageManager()->FieldValueById(
					$id,
					'page_title'
				),
				array(
					"class" => "app_input",
					"id" => "page_title"
				)
			)
		)
		->addRow(
			$this->__("Meta Keywords" . App::Helper('Html')->helpTag('page-manager-meta-keyword')),
			App::Helper("Html")
				->textareaTag(
					'data[Page][meta_keywords]',
					App::PageManager()
						->FieldValueById(
							$id,
							'meta_keywords'
						),
					array(
						"class" => "app_input",
						"id" => "meta_keywords"
					)
				)
			)
		->addRow(
			$this->__("Meta Descriptions" . App::Helper('Html')->helpTag('page-manager-meta-desc')),
			App::Helper("Html")->textareaTag(
				'data[Page][meta_description]', 
				App::PageManager()->FieldValueById(
					$id,
					'meta_description'
				),
				array(
					"style"=>"overflow:none",
					"class" => "app_input",
					"id" => "meta_description"
				)
			)
		);
     }
?>

<?php 
	$Grid->addRow(
		"Title",
		App::Helper("Html")->inputTag(
			'data[Page][title]',
			App::PageManager()->FieldValueById(
				$id,
				'title'
			),
			array(
				"class" => "app_input",
				"id" => "title"
			)
		)
	); ?>

<?php
    $Grid->addRow(
		"Content",
		App::Helper("Html")->textareaTag('data[Page][content]', 
		App::PageManager()->FieldValueById($id,'content'),
		array(
			"rows" => "22",
			"class" =>((App::PageManager()->FieldValueById($id,'richtexteditor')=='No') ? "textarea large" : "large richtexteditor") ,
			"id" => "page_content")
		)
	);
?>

<?php
	if( $action != 'create'){
		$Grid->addRow(
			'',
			App::Helper('Html')->checkboxTag(
				'data[Page][richtexteditor]',
				array(
					'Yes'=>"Richtext(WYSIWYG) Editor"),
					App::PageManager()->FieldValueById($id,'richtexteditor'),
					array(
						"onclick"=>"chnageState({$id})"
					)
				) . 
				App::Helper('Html')->helpTag('page-manager-meta-richtexteditor')
		);
	}
?>

<?php 	$Grid->Render(); ?>

<?php App::Helper('Toolbar')->setBtnSave()->setBtnBack()->setFormJustified(true)->Render(array('code'=>'page_manager_bottom'));?>
</form>
 
 <?php    echo App::Module('AdminPanelUi')->pageCodesList('Html'); ?>
 
<?php App::Helper('JavaScript')->appForm('.pagemanager_form'); ?>